$(document).ready(function(){
	//Botones Show/Hide Caja de login
	$("#box-close").click(function(){
		$("#box-login").animate({
			opacity: "hide"
		 }, 300);
	});
	$('#btn-login').click(function(){
		var action = ($("#box-login").css("display") == 'none')? "show": "hide";
		
		$("#box-login").animate({
			opacity: action
		 }, 300, function(){
			 if(action == "show")
				 $("#int-email").focus();
		 });
	});
	
	//Login de usuario Formulario
	$("#frm-login").submit(function(){
		$("#res_login").html('<img src="'+base_url+'application/images/loading.gif" width="10" height="10">');
		$.getJSON(base_url+"services/user/login",
		{
			email: this.email.value,
			password: this.password.value
		},
		function(data){
			if(data.status.code == 200){
				window.location = base_url+lang_url;
			}
			$("#res_login").text(data.status.message);
		});
		return false;
	});
	
	//Precarga de imagenes
	$(".img-lazyload").lazyload({
		effect: "fadeIn"
	});
	
	//Top link
	$('#top-link').topLink({
		min: 400,
		fadeSpeed: 500
	});
	//Top link - smoothscroll
	$('#top-link').click(function(e) {
		e.preventDefault();
		$.scrollTo(0,300);
	});
	
	/*Buscador de peliculas, series y actores*/
	$(".frm-search.frm1").submit(function(){
		return false;
	});
	$("#search_acom").autocomplete(base_url+'services/search/query', {
		multiple: 	true,
		max:		10,
		scroll: 	false,
		highlight:	false,
		width:		258,
		dataType: 	"json",
		parse: function(data) {
			return $.map(data.result_search, function(row) {
				return {
					data: row,
					value: row.title,
					result: row.url_web
				}
			});
		},
		formatItem: function(item) {
			return '<img src="'+item.image+'" width="30" height="34"> <span>'+item.title+'</span>';
		}
	}).result(function(e, item) {
		this.value = '';
		window.location = base_url+util.getSubLang(util.getCookie('p_lang'))+item.url_web;
	});
	
	
	//evento a login facebook
	$('.acces-facebook').click(function(){
		$(this).css('display', 'none');
		$('.loader-face').css('display', 'block');
	});
});

$(window).load(function() {
	/*Banner en el home*/
	if(jQuery().nivoSlider){
		$('#slider').nivoSlider({
	        animSpeed: 500, // Slide transition speed
	        pauseTime: 5000, // How long each slide will show
	        directionNav: false, // Next & Prev navigation
	        directionNavHide: true, // Only show on hover
	        controlNav: false, // 1,2,3... navigation
	        manualAdvance: false, // Force manual transitions
	        captionOpacity: 0.8, // Universal caption opacity
	        prevText: 'Prev', // Prev directionNav text
	        nextText: 'Next', // Next directionNav text
	    });
	}
});


var 

mplayer = {
	loadPlayer: function(link){
		var htm = '<object classid="clsid:67DABFBF-D0AB-41fa-9C46-CC0F21721616" width="620" height="350" codebase="http://go.divx.com/plugin/DivXBrowserPlugin.cab">'+
			'<param name="custommode" value="none" />'+
		'<param name="previewImage" value="'+base_url+'application/images/jplayer_tumb.jpg" />'+
		'<param name="src" value="'+link+'" />'+
		'<embed type="video/divx" src="'+link+'" custommode="none" width="620" height="350" previewImage="'+base_url+'application/images/jplayer_tumb.jpg"  pluginspage="http://go.divx.com/plugin/download/">'+
		'</embed>'+
	'</object><br />No video?<a href="http://www.divx.com/software/divx-plus/web-player" target="_blank">Download</a> the DivX Plus Web Player. <a href="'+base_url+'application/images/Pasos-Instalar-Web-Player.jpg" target="_blank">Tutorial</a>';
		
		$("#absoluto").html(htm);
		$("#absoluto").show();
		
		$("#reproductor").remove();
	}
},




util = {
	setCookie: function(cookieName,cookieValue,expires,path,domain,secure) { 
	   document.cookie= 
	   escape(cookieName)+'='+escape(cookieValue) 
	   +(expires?'; EXPIRES='+expires.toGMTString():'') 
	   +(path?'; PATH='+path:'') 
	   +(domain?'; DOMAIN='+domain:'') 
	   +(secure?'; SECURE':''); 
   },
   getCookie: function(cookieName) { 
	   var cookieValue=null, posValue, endPos,  
	   posName=document.cookie.indexOf(escape(cookieName)+'='); 
	   if (posName!=-1) { 
		   posValue=posName+(escape(cookieName)+'=').length; 
		   endPos=document.cookie.indexOf(';',posValue); 
		   if (endPos!=-1) cookieValue=unescape(document.cookie.substring(posValue,endPos)); 
		   else cookieValue=unescape(document.cookie.substring(posValue)); 
	   } 
	   return cookieValue; 
   },
   
   
   getSubLang: function(lang){
	   switch(lang){
	   		case 'eng': return 'en/'; break;
	   		case 'spa': return ''; break;
	   }
	   return '';
   },
   
   dump: function(arr,level) {
		var dumped_text = "";
		if(!level) level = 0;
		
		//The padding given at the beginning of the line.
		var level_padding = "";
		for(var j=0;j<level+1;j++) level_padding += "    ";
		
		if(typeof(arr) == 'object') { //Array/Hashes/Objects 
			for(var item in arr) {
				var value = arr[item];
				
				if(typeof(value) == 'object') { //If it is an array,
					dumped_text += level_padding + "'" + item + "' ...\n";
					dumped_text += util.dump(value,level+1);
				} else {
					dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
				}
			}
		} else { //Stings/Chars/Numbers etc.
			dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
		}
		return dumped_text;
	}
};